//购物车模块
export default {
    namespaced: true,
    state() {
        return {
            cartList: [], //购物车列表信息
            cartTotal: {} //购物车的统计信息
        }
    },
    getters: {
        //建立快捷访问
        //商品数量
        goodsCount: state => state.cartTotal.goodsCount,
        //商品价格
        goodsAmount: state => state.cartTotal.goodsAmount,
        //选中的商品总价格
        checkedGoodsAmount: state => state.cartTotal.checkedGoodsAmount,
        //选中的商品总数量
        checkedGoodsCount: state => state.cartTotal.checkedGoodsCount,

    },
    mutations: {
        //1.设置购物车数据
        setCartData(state, data) {
            state.cartList = data.cartList
            state.cartTotal = data.cartTotal
        }
    },
    actions: {
        //1.获取购物车数据
        async getInitData(context) {
            let res = await uni.$http.get('/cart/index')
            // console.log(res); // { cartList[],cartTotal{} } 
            context.commit('setCartData', res)
        }
    }
}
